package org.example.gradle.base.config.mq.cdtc;

import gradle.rabbit.common.constants.RabbitTemplateConstant;
import jakarta.annotation.Resource;
import org.springframework.amqp.core.Binding;
import org.springframework.amqp.core.BindingBuilder;
import org.springframework.amqp.rabbit.core.RabbitAdmin;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;


/**
 * CDTC 绑定交换机和队列
 *
 */
@Configuration
public class CdtcBindMqConfiguration {

    /**
     * 注入RabbitAdmin
     */
    @Resource(name = RabbitTemplateConstant.PRIMARY_RABBIT_TEMPLATE)
    private RabbitAdmin rabbitAdmin;

    /**
     * CDTC对接各模块交换机
     */
    @Resource
    CdtcExchangeMqConfiguration cdtcExchange;
    /**
     * CDTC对接各模块队列配置
     */
    @Resource
    CdtcQueueMqConfiguration cdtcQueue;

    /**
     * 绑定 CDTC跨境回执监控队列-进口-队列
     */
    @Bean
    public Binding cdtcReturnCrossBroderIbQueueBinding() {
        Binding binding = BindingBuilder.bind(cdtcQueue.cdtcReturnCrossBorderIbMonitorQueue()).to(cdtcExchange.cdtcReturnCrossBorderIbExchange());
        rabbitAdmin.declareBinding(binding);
        return binding;
    }
}
